﻿using System;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(USInternalKeyframe)), CanEditMultipleObjects]
public class USPropertyKeyframeInspector : Editor
{
    private SerializedProperty brokenTangents;
    private SerializedProperty inTangent;
    private SerializedObject keyframes;
    private SerializedProperty outTangent;
    private SerializedProperty time;
    private SerializedProperty value;

    private void OnEnable()
    {
        this.keyframes = new SerializedObject(base.targets);
        this.time = this.keyframes.FindProperty("time");
        this.value = this.keyframes.FindProperty("value");
        this.inTangent = this.keyframes.FindProperty("inTangent");
        this.outTangent = this.keyframes.FindProperty("outTangent");
        this.brokenTangents = this.keyframes.FindProperty("brokenTangents");
    }

    public override void OnInspectorGUI()
    {
        this.keyframes.Update();
        EditorGUILayout.PropertyField(this.time, new GUIContent("触发时间"), new GUILayoutOption[0]);
        EditorGUILayout.PropertyField(this.value, new GUIContent("值"), new GUILayoutOption[0]);
        EditorGUILayout.PropertyField(this.inTangent, new GUIContent("内切"), new GUILayoutOption[0]);
        EditorGUILayout.PropertyField(this.outTangent, new GUIContent("外切"), new GUILayoutOption[0]);
        EditorGUILayout.PropertyField(this.brokenTangents, new GUIContent("断切"), new GUILayoutOption[0]);
        bool flag = (Event.current != null) && ((Event.current.type == EventType.ValidateCommand) && (Event.current.commandName == "UndoRedoPerformed"));
        if (this.keyframes.ApplyModifiedProperties() || flag)
        {
            foreach (UnityEngine.Object obj2 in base.targets)
            {
                if (obj2 is USInternalKeyframe)
                {
                    USInternalKeyframe keyframe = obj2 as USInternalKeyframe;
                    if (!flag)
                    {
                        Undo.RegisterUndo(keyframe.curve, "观察器");
                    }
                    keyframe.curve.ValidateKeyframeTimes();
                    keyframe.curve.BuildAnimationCurveFromInternalCurve();
                }
            }
        }
    }
}

